package es.mahulo.battleship.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement

@Entity
@Table(name="GAME")
public class Game {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID")
	private Long id;

	@OneToMany(targetEntity=Player.class,mappedBy="game",fetch=FetchType.EAGER,cascade = {CascadeType.ALL })
	private List<Player> players;
	
	@Column(name="STATUS")
	@Enumerated(EnumType.STRING)
	private GameStatus status;
	
	@OneToOne(cascade = {CascadeType.PERSIST })
	@JoinColumn(name="ID_GAME_CONFIG") 
	private GameConfig gameConfig;

	public Game() {

	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<Player> getPlayers() {
		return players;
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
	}

	public GameStatus getStatus() {
		return status;
	}

	public void setStatus(GameStatus status) {
		this.status = status;
	}
	
	public GameConfig getGameConfig() {
		return gameConfig;
	}

	public void setGameConfig(GameConfig gameConfig) {
		this.gameConfig = gameConfig;
	}

	public String toString() {
		return "Game { Id: " + 
					id + 
					" players: " 
					+ players 
					+ " status: " 
					+ status 
					+ " config: " 
					+  gameConfig 
					+ " } ";
	}
}
